﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 组合键的类
/// </summary>
[CreateAssetMenu(menuName = "MyScript/Input/CombinedOrMultiButtonData")]
public class CombinedOrMultiButtonData : ButtonData
{
    [SerializeField] private GameTypeDefine.BUTTON_ID[] m_button = { GameTypeDefine.BUTTON_ID.NONE };

    private bool m_boolTemp;

    public void CheckMulti(Hashtable buttonHash)
    {
        for (int i = 0, length = m_button.Length; i < length; i++)
        {
            m_boolTemp = (bool)buttonHash[m_button[i]];

            if (m_boolTemp)
            {
                break;
            }
        }

        InvokeButtonEvent();
    }

    public void CheckCombined(Hashtable buttonHash)
    {
        m_boolTemp = true;

        for (int i = 0, length = m_button.Length; i < length; i++)
        {
            if (!(bool)buttonHash[m_button[i]])
            {
                m_boolTemp = false;

                break;
            }
        }

        InvokeButtonEvent();
    }

    private void InvokeButtonEvent()
    {
        if (!m_boolTemp && !m_pressFlag)
        {
            return;
        }

        if (m_boolTemp && !m_pressFlag)
        {
            m_pressFlag = true;
            EventMgr.InvokeEvent(GameTypeDefine.EVENT_ID.BUTTON_DOWN, m_eventArgs);
        }

        if (m_boolTemp && m_pressFlag)
        {
            m_eventArgs.PressedTime += Time.time;
            EventMgr.InvokeEvent(GameTypeDefine.EVENT_ID.BUTTON_PRESSED, m_eventArgs);
        }

        if (!m_boolTemp && m_pressFlag)
        {
            m_pressFlag = false;
            EventMgr.InvokeEvent(GameTypeDefine.EVENT_ID.BUTTON_UP, m_eventArgs);
            m_eventArgs.PressedTime = 0;
        }
    }
}
